CentOS 6
Sponsored Link

Puppet - How to Use [service resource]
2014/01/26
 
This is the exmaples for service resource.
[1] It manages the configuration to keep "httpd" is running.
[root@dlp ~]#
vi /etc/puppet/manifests/site.pp
service { 'httpd':
    name   => 'httpd',
    ensure => running,
}
[2] It manages the configuration to keep "httpd" is running. If "httpd" is not installed, "httpd" can not start of course, so it manages the configuration to keep "httpd" is installed with "require" parameter like follows.
[root@dlp ~]#
vi /etc/puppet/manifests/site.pp
package { 'httpd':
    provider => yum,
    ensure   => installed,
}
service { 'httpd':
    name    => 'httpd',
    ensure  => running,
    require => Package['httpd'],
}
[3] It manages the configuration to keep "httpd" is not running. If running, it stops.
[root@dlp ~]#
vi /etc/puppet/manifests/site.pp
service { 'httpd':
    name   => 'httpd',
    ensure => stopped,
}
[4] It restarts "httpd" when the file "/etc/httpd/conf/httpd.conf" is updated.
[root@dlp ~]#
vi /etc/puppet/manifests/site.pp
file { '/etc/httpd/conf/httpd.conf':
    ensure => file,
    owner  => 'root',
    group  => 'root',
    mode   => 644,
    source => 'puppet://dlp.srv.world/extra_files/httpd.conf',
    notify => Service['httpd'],

}
service { 'httpd':
    name   => 'httpd',
    ensure => running,
}
 
Tweet